#define SIZE 9
#define nr 'n'
#define bl 'b'
#define ab ' '
#define X 'x'
#define tmp 'X'
/*--------------------------------------------------------------------------------------------------------------------------------------------*/
														/*PROTOTYPE DE RETOURNE PION N/B DES FONCTIONS*/
void bl_return_pion(int,int,int);
int  bl_return_ht_gch(int ,int,int);
int  bl_return_ht_ct(int ,int,int);
int  bl_return_ht_drt(int ,int,int);
int  bl_return_ml_gch(int ,int,int);
int  bl_return_ml_drt(int ,int,int);
int  bl_return_bs_gch(int ,int,int);
int  bl_return_bs_ct(int ,int,int);
int  bl_return_bs_drt(int ,int,int);
/*--------------------------------------------------------------------------------------------------------------------------------------------*/
													   /*VARIABLES GENERALE*/
int tab[SIZE+1][SIZE];
/*--------------------------------------------------------------------------------------------------------------------------------------------*/
														/*FONCTION PRINCIPALE DE RETOURNEMENT DES PIONS B*/
void bl_return_pion(int  caract,int ligne,int colonne)
{
 int i=ligne;		
 int j=colonne;
 int b=0;
 int n=0;
 if(i>1 && j>1)
 tab[i][j]=bl_return_ht_gch(tab[i-1][j-1],i,j);
 if(i>1)
 tab[i][j]=bl_return_ht_ct(tab[i-1][j],i,j);
 if(i>1 && j<SIZE-1)
 tab[i][j]=bl_return_ht_drt(tab[i-1][j+1],i,j);
 if(j>1)
 tab[i][j]=bl_return_ml_gch(tab[i][j-1],i,j);
 if(j<SIZE-1)
 tab[i][j]=bl_return_ml_drt(tab[i][j+1],i,j);
 if(i<SIZE-1 && j>1)
 tab[i][j]=bl_return_bs_gch(tab[i+1][j-1],i,j);
 if(i<SIZE-1)
 tab[i][j]=bl_return_bs_ct(tab[i+1][j],i,j);
 if(i<SIZE-1 && j<SIZE-1)
 tab[i][j]=bl_return_bs_drt(tab[i+1][j+1],i,j);
 for(i=0;i<SIZE;i++)
 {
  for(j=0;j<SIZE;j++)
  {
   if(tab[i][j]== X)
   {		    
    tab[i][j]= ab;
   }
  }
 }
}
/*--------------------------------------------------------------------------------------------------------------------------------------------*/
														/*FONCTION SECONDAIRE DE RETOURNEMENT DES PIONS B*/
int  bl_return_ht_gch(int  case_b,int col,int lig)
{
 int i;
 int j;
 int  test;
 int  case_tmp = bl;
 i=col;
 j=lig;
 if(case_b==nr)
 {
  if(i>1 && j>1)
  {
   do
   {
    test=tab[i-1][j-1];
    i=i-1;
    j=j-1;
   }
   while(test==nr);
   if(test==bl)
   {
    do
    {
     case_tmp=tab[col-1][lig-1];
     tab[col-1][lig-1]=bl;
     col=col-1;
     lig=lig-1;
    }
    while(case_tmp==nr);
    case_b=bl;
   }
  }
 }
 return case_tmp;
}
/*--------------------------------------------------------------------------------------------------------------------------------------------*/
int  bl_return_ht_ct(int  case_b,int col,int lig)
{
 int i;
 int j;
 int  test; 
 int  case_tmp=bl;
 i=col;
 j=lig;
 if(case_b==nr)
 {
  if(i>1)
  {
   do
   {
    test=tab[i-1][j];
    i=i-1;
   }
   while(test==nr);
   if(test==bl)
   {
    do
    {
     case_tmp=tab[col-1][lig];
     tab[col-1][lig]=bl;
     col=col-1;
    }
    while(case_tmp==nr);
    case_b=bl;
  }
  }
 }
 return case_tmp;
}
/*--------------------------------------------------------------------------------------------------------------------------------------------*/
int  bl_return_ht_drt(int  case_b,int col,int lig)
{
 int i;
 int j;
 int  test;
 int  case_tmp=bl;
 i=col;
 j=lig;
 if(case_b==nr)
 {
  if(i>1 && j<SIZE-1)
  {
   do
   { 
    test=tab[i-1][j+1];
    i=i-1;
    j=j+1;
   }
   while(test==nr);
   if(test==bl)
   {
    do
    {
     case_tmp=tab[col-1][lig+1];
     tab[col-1][lig+1]=bl;
     col=col-1;
     lig=lig+1;
    }
    while(case_tmp==nr);
    case_b=bl;
   }
  }
 }
 return case_tmp;
}
/*--------------------------------------------------------------------------------------------------------------------------------------------*/
int  bl_return_ml_gch(int  case_b,int col,int lig)
{
 int i;
 int j;
 int  test;
 int  case_tmp=bl;
 i=col;
 j=lig;
 if(case_b==nr)
 {
  if(j>1)
  {
   do
   {
    test=tab[i][j-1];
    j=j-1;
   }
   while(test==nr);
   if(test==bl)
   {
    do
    {
     case_tmp=tab[col][lig-1];
     tab[col][lig-1]=bl;
     lig=lig-1;
    }
    while(case_tmp==nr);
    case_b=bl;
   }
  }
 }
 return case_tmp;
}
/*--------------------------------------------------------------------------------------------------------------------------------------------*/
int  bl_return_ml_drt(int  case_b,int col,int lig)
{
 int i;
 int j;
 int  test;
 int  case_tmp=bl;
 i=col;
 j=lig;
 if(case_b==nr)
 {
  if(i<SIZE-1)
  {
   do
   {
    test=tab[i][j+1];
    j=j+1;
   }
   while(test==nr);
   if(test==bl)
   {
    do
    {
     case_tmp=tab[col][lig+1];
     tab[col][lig+1]=bl;
     lig=lig+1;
    }
    while(case_tmp==nr);
    case_b=bl;
   }
  }
 }
 return case_tmp;
}
/*--------------------------------------------------------------------------------------------------------------------------------------------*/
int  bl_return_bs_gch(int  case_b,int col,int lig)
{
 int i;
 int j;
 int  test;
 int  case_tmp=bl;
 i=col;
 j=lig;
 if(case_b==nr)
 {
  if(i<SIZE-1 && j>1)
  {
   do
   {
    test=tab[i+1][j-1];
    i=i+1;
    j=j-1;
   }
   while(test==nr);
   if(test==bl)
   {
    do
    {
     case_tmp=tab[col+1][lig-1];
     tab[col+1][lig-1]=bl;
     col=col+1;
     lig=lig-1;
    }
    while(case_tmp==nr);
    case_b=bl;
   }
  }
 }
 return case_tmp;
}
/*--------------------------------------------------------------------------------------------------------------------------------------------*/
int  bl_return_bs_ct(int  case_b,int col,int lig)
{
 int i;
 int j;
 int  test;
 int  case_tmp=bl;
 i=col;
 j=lig;
 if(case_b==nr)
 {
  if(i<SIZE-1)
  {
   do
   {
    test=tab[i+1][j];
    i=i+1;
   }
   while(test==nr);
   if(test==bl)
   {
    do
    {
     case_tmp=tab[col+1][lig];
     tab[col+1][lig]=bl;
     col=col+1;
    }
    while(case_tmp==nr);
    case_b=bl;
   }
  }
 }
 return case_tmp;
}
/*--------------------------------------------------------------------------------------------------------------------------------------------*/
int  bl_return_bs_drt(int  case_b,int col,int lig)
{
 int i;
 int j;
 int  test;
 int  case_tmp=bl;
 i=col;
 j=lig;
 if(case_b==nr)
 {
  if(i<SIZE-1 && j<SIZE-1)
  {
   do
   {
    test=tab[i+1][j+1];
    i=i+1;
    j=j+1;
   }
   while(test==nr);
   if(test==bl)
   {
    do
    {
     case_tmp=tab[col+1][lig+1];
     tab[col+1][lig+1]=bl;
     col=col+1;
     lig=lig+1;
    }
    while(case_tmp==nr);
    case_b=bl;
   }
  }
 }
 return case_tmp;
}
/*--------------------------------------------------------------------------------------------------------------------------------------------*/
